package top.chukongxiang.project.base.utils;

import java.util.Random;

public class RandomUtils {

    public static final String NUMBER_STR = "0123456789";
    public static final String STR_ALL = "@#$abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + NUMBER_STR;
    public static final Random RANDOM = new Random();
    /**
     * 返回指定长度的随机数
     * @param len
     * @return
     */
    public static String getChars(int len, String values) {
        StringBuilder stringBuilder = new StringBuilder();
        if (len > 16) {
            len = 16;
        }
        for (int i = 0; i < len; i++) {
            int f = (int) (Math.random() * values.length());
            stringBuilder.append(STR_ALL.charAt(f));
        }
        return stringBuilder.toString();
    }

    public static long getLong(int len, String values) {
        String chars = getChars(len, values);
        return Long.parseLong(chars);
    }

    public static int getInt(int len, String values){
        String chars = getChars(len, values);
        return Integer.parseInt(chars);
    }

    // min <= result < max
    public static int getInt(int min, int max) {
        return RANDOM.nextInt(max) % (max - min + 1) + min;
    }

}
